#include <iostream>
#include "../../common/detail.hpp"
#include "../../server/rpc_server.hpp"

void Add(const Json::Value &params, Json::Value &result){
    int num1 = params["num1"].asInt();
    int num2 = params["num2"].asInt();
    result = num1 + num2;
}

int main(){
    myrpc::initLoggers();

    // 注册对应的服务
    std::unique_ptr<myrpc::server::SDescribeBuilder> builder(new myrpc::server::SDescribeBuilder());
    builder->setMethod("Add");
    builder->setParamDescribe("num1", myrpc::server::VType::INTEGRAL);
    builder->setParamDescribe("num2", myrpc::server::VType::INTEGRAL);
    builder->setResultType(myrpc::server::VType::INTEGRAL);
    builder->setServiceCallBack(Add);

    // 创建服务器
    myrpc::Address addr = std::make_pair("127.0.0.1", 28080);
    auto server = std::make_shared<myrpc::server::RpcServer>(addr);
    server->registryMethod(builder->build());
    server->start();

    mylog::shutdown();
    return 0;
}